package com.bean.javaconfig;

import com.bean.xml.Klass;
import com.bean.xml.School;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class JavaConfigTest {

    public static void main(String[] args) {
        // TODO 获取Spring容器中的Bean。
        // AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        // context.register(JavaConfig.class);
        // context.refresh();

        // 通过xml配置<context:component-scan > 也可以
        ApplicationContext context = new ClassPathXmlApplicationContext("javaconfigContext.xml");

        // TODO 第三方类库中的Schllo的实例school自动装载到了klass中
        Klass klass = (Klass) context.getBean("klass");
        klass.getSchool().ding();

        // TODO Spring通过JavaConfig创建的实例是单例
        School schoolC = (School) context.getBean("school");
        School schoolD = (School) context.getBean("school");
        System.out.println(schoolC == schoolD);

        // context.close();
    }
}
